//
//  VVVisitorTableViewController.swift
//  Weibo
//
//  Created by 王惠平 on 2017/3/27.
//  Copyright © 2017年 Will Wang. All rights reserved.
//

import UIKit

class VVVisitorTableViewController: UITableViewController {


    //是否登录标记
    //var isLogin: Bool = VVUserAccount.loadUserAccount()?.access_token != nil
    var isLogin: Bool = VVUserAccountViewModel.sharedViewModel.islogin
    
    //访客视图信息
    var visitorView : VVVisitorView?
    
    override func viewDidLoad() {
        super.viewDidLoad()

        if isLogin {
            
            super.loadView()
        } else {
            
            //自定义访客视图
            visitorView = VVVisitorView()
            
            //设置闭包
            visitorView?.loginClosure = { [weak self] in
                
                self?.enterOAuth()
                //print("我是闭包调用过来的")
            }
            
            view = visitorView
            
            //没有登录设置导航栏按钮
            setupNAVUI()
        }
        
    
    }
    
    func setupNAVUI() {
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", target: self, action: #selector(registerButtonAction))
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", target: self, action: #selector(loginButtonAction))
        
        
    }
    
    func registerButtonAction() {
        
        enterOAuth()
        //print("注册")
    }
    
    func loginButtonAction() {
        
        enterOAuth()
        //print("登录")
    }
    
    //进入OAuth登录界面
    private func enterOAuth() {
        
        let vc = VVOAuthViewController()
        
        let nav = VVNavigationViewController(rootViewController: vc)
        
        self.present(nav, animated: true, completion: nil)
        
    }

}
